//
//  DKLoginMsgCodeView.m
//  DanKU
//
//  Created by 吴斌 on 2023/9/19.
//

#import "DKLoginMsgCodeView.h"
@interface DKLoginMsgCodeView()<UITextFieldDelegate>
@end
@implementation DKLoginMsgCodeView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = DK_Hex(@"#F7F7F8");
        self.layer.borderWidth = 0;
        self.layer.borderColor = DK_Hex(@"#4566FF").CGColor;
        self.layer.cornerRadius = 14;
        self.clipsToBounds = YES;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_LoginMsgCodeTextField = [[UITextField alloc] init];
    self.dk_LoginMsgCodeTextField.textColor = DK_Hex(@"#333333");
    self.dk_LoginMsgCodeTextField.font = DK_FONT_Regular(15);
    self.dk_LoginMsgCodeTextField.placeholder = @"Verification code";
    self.dk_LoginMsgCodeTextField.delegate = self;
    [self addSubview:self.dk_LoginMsgCodeTextField];
    [self.dk_LoginMsgCodeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(20)));
        make.right.equalTo(@(-DK_IsWidthScale(20)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
    }];
}
- (NSString *)getLoginCode{
    return self.dk_LoginMsgCodeTextField.text;
}
#pragma mark UITextFieldDelegate
-(void)textFieldDidBeginEditing:(UITextField *)textField{//开始编辑
    if(self.StartEditPhoneBlock){
        self.StartEditPhoneBlock();
    }
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString *phoneCode = [textField.text stringByReplacingCharactersInRange:range withString:string];
    if(phoneCode.length > 0){
        self.layer.borderWidth = 0.5;
    }else{
        self.layer.borderWidth = 0;
    }
    if(phoneCode.length > 0){
        if(self.goCheckMsgCodeBlock){
            self.goCheckMsgCodeBlock(false);
        }
    }else{
        if(self.goCheckMsgCodeBlock){
            self.goCheckMsgCodeBlock(true);
        }
    }
    return YES;
}
@end
